# yield  生成器
# 和 return 用法一样,含义不同
#  return   结束函数

# -------------list  tuple  dict  set  str-------
# yield == generator  通过上一个值计算得出下一个值,记录了一个值以及一套运算规则
#   gen 占用内存空间小

def fun1():
    for i in range(1,6):
        print (i)
     #  return 结束运行
lista = list(fun1())
print(lista)

# def fun1():
#     for i in range(1,6):
#         yield i
#         # <generator object fun1 at 0x0000016845110DB0>
# lista = list(fun1())
# print(lista)
#  <generator>
#  类似于容器 ,
#  边循环边计算,每次计算才返回一个值
gen = fun1()
#print(list(gen))
# for i in gen:
#     print(i)
# print(next(gen))
# print(next(gen))
# print(next(gen))
# print(next(gen))
# print(next(gen))
# print(next(gen))
# print(next(gen))
# StopIteration  停止迭代



# list1 = [i for i in range(1,1000000000000000000)]
# print(list1)

# def genlist():
#     for i in range(1,10000000000000000000):
#         yield i
# gen = genlist()
# for i in gen:
#     print(i)